package cn.entity.impor.test;

import java.util.List;
import java.util.Scanner;

import Impor.StuDaoMySqlImpl;
import entity.StuDao;
import entity.student;
/**
 *  测试类
 * @author key1032722147
 *
 */
public class test {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = 0;
		System.out.println("请选择你需要的操作，1增  2 改   3删 4查  5添加考试成绩  6分页查询");
		switch(sc.nextInt()) {
			case 1:
				student st = new student();
				StuDao stAdd = new StuDaoMySqlImpl();
				System.out.println("请输入要增加的学生的学号");
				st.setStuno(sc.nextInt());
				System.out.println("请输入要增加的学生的名字");
				st.setSname(sc.next());
				System.out.println("请输入要增加的学生的班级");
				st.setGradeid(sc.nextInt());
				num = stAdd.add(st);
				if (num > 0) {
					System.out.println("增加成功");
				} else {
					System.out.println("增加失败");
				}
				break;
			case 2:
				student st2 = new student();
				StuDao stUpda = new StuDaoMySqlImpl();
				System.out.println("请输入要更新的学生的学号");
				st2.setStuno(sc.nextInt());
				System.out.println("请输入要学生要调换的班级");
				st2.setGradeid(sc.nextInt());
				num = stUpda.update(st2);
				if (num > 0) {
					System.out.println("更新成功");
				} else {
					System.out.println("更新失败");
				}
				break;
			case 3:
				student st3 = new student();
				StuDao stDel = new StuDaoMySqlImpl();
				System.out.println("请输入要删除的学生的学号");
				st3.setStuno(sc.nextInt());
				num = stDel.del(st3);
				if (num > 0) {
					System.out.println("删除成功");
				} else {
					System.out.println("删除失败");
				}
				break;
			case 4:
				StuDao dao = new StuDaoMySqlImpl();
				System.out.println("请输入学号：");
				int stuno = sc.nextInt();
				student st4 = dao.get(stuno);
			if (st4 == null) {
					System.out.println("查无此人！");
					return;
				}
				System.out.println("找到了！");
				System.out.println(st4);
				break;
			case 5:
				StuDaoMySqlImpl score1 = new StuDaoMySqlImpl();
				System.out.println("请输入成绩编号");
				int id = sc.nextInt();
				System.out.println("请输入分数");
				float score = sc.nextFloat();
				System.out.println("请输入考试学生的学号");
				int st_no = sc.nextInt();
				System.out.println("请输入科目编号");
				int sb_no = sc.nextInt();
				int row = score1.addScore(id,score,st_no,sb_no);
				if (row > 0) {
					System.out.println("成绩添加成功");
				} else {
					System.out.println("成绩添加失败了");
				}
				break;
			case 6:
					StuDaoMySqlImpl sear = new StuDaoMySqlImpl();
					System.out.println("请输入要查询的页号：");
					int pageNo = sc.nextInt();
					System.out.println("请输入要每页要显示的行数");
					int pageSize = sc.nextInt();
					List<student> list =sear.find(pageNo, pageSize);
					for (student stu:list) {
						System.out.println(stu);
					}
				break;
				default:
				System.out.println("选择有误，请重新启动！");
	}
	
	}

}
